package com.wu.system.controller.wx;

import com.wu.common.page.PageResult;
import com.wu.common.utils.Result;
import com.wu.dao.weixin.vo.WeixinClanVO;
import com.wu.dao.weixin.vo.WeixinMenuVO;
import com.wu.entity.weixin.po.WeixinClan;
import com.wu.service.sys.query.SysUserQuery;
import com.wu.service.sys.query.WeixinClanQuery;
import com.wu.service.weixin.service.WxClanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 战队管理
 *
 * @author wzd 
 */
@RestController
@RequestMapping("wx/clan")
@AllArgsConstructor
@Tag(name="战队管理")
public class WxClanController {
    @Autowired
    private WxClanService wxClanService;


    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('sys:user:page')")
    public Result<PageResult<WeixinClanVO>> page(@Valid WeixinClanQuery query){
        PageResult<WeixinClanVO> page = wxClanService.page(query);

        return Result.ok(page);
    }


    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('sys:user:delete')")
    public Result<String> delete(@RequestBody List<String> idList){
        wxClanService.deleteByIds(idList);
        return Result.ok();
    }


    @DeleteMapping(value = "/dissolve")
    @Operation(summary = "解散")
    @PreAuthorize("hasAuthority('sys:user:delete')")
    public Result<String> dissolve(@RequestBody List<String> idList){
        idList.forEach(item->{
            WeixinClan entity = new WeixinClan();
            entity.setId(Long.valueOf(item));
            entity.setStatus(1);
            wxClanService.updateById(entity);
        });
        return Result.ok();
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('sys:user:save')")
    public Result<String> save(@RequestBody @Valid WeixinClanVO vo){
        // 保存
        wxClanService.save(vo);
        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('sys:user:update')")
    public Result<String> update(@RequestBody @Valid WeixinClan vo){
        wxClanService.updateById(vo);
        return Result.ok();
    }

}
